<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  

  <script>
    function Person(name) {
      this.name = name;
    }
    Person.prototype.say = function() {
      console.log(`My Name is ${this.name}`);
    }


    var per = new Person("李明");
    per.say();

    // TODO: 产生实例
    function myNew(fn, ...args) {
      // 创建一个空对象
      const obj = {}
      // 改原型
      obj.__proto__ = fn.prototype
      // 执行构造函数
      const res = fn.apply(obj, args)

      return typeof res === 'object' ? res : obj;
    }

    var par2 = myNew(Person, "lisi");
    console.log(par2);

  </script>
</body>
</html>